package com.fuershiye.woman.monitor.utils;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class Math {

	public static final String HUNDRED_MARK = "%";
	public static final String THOUSAND_MARK = "‰";

	public static final int HUNDRED = 100;
	public static final int THOUSAND = 1000;

	/**
	 * @param a 	分子
	 * @param b 	分母
	 * @param c 	小数位数
	 * @return 	100% 	百分制的数值(四舍五入的数值)
	 */
	public static String get100(int a, int b, int c) {
		return getMathValue(a, b, c, HUNDRED);
	}

	/**
	 * @param a 	分子
	 * @param b 	分母
	 * @param c 	小数位数
	 * @return 	1000‰ 	千分制的数值(四舍五入的数值)
	 */
	public static String get1000(int a, int b, int c) {
		return getMathValue(a, b, c, THOUSAND);
	}

	/**
	 * @param a 	分子
	 * @param b 	分母
	 * @param c 	小数位数
	 * @param d 	进制(100:100%; 1000:1000‰)
	 * @return 	四舍五入的数值
	 */
	public static String getMathValue(int a, int b, int c, int d) {
		String str = "";
		switch (c) {
		case 0:
			str = "#";
			break;
		case 1:
			str = "#.0";
			break;
		case 2:
			str = "#.00";
			break;
		case 3:
			str = "#.000";
			break;
		case 4:
			str = "#.0000";
			break;
		default:
			str = "#.00";
		}
		DecimalFormat df = new DecimalFormat(str);
		float num = (float) (a * d) / b;
		return df.format(num);
	}

	public static boolean isNull(Double value) {
		if(null==value || value.equals("") || value.equals(0) || value.equals(0.0) || value.equals(0.00) || value.equals(00.00)){
			return true;
		}
		return false;
	}

	public static double divideAB(Double a, Double b) {
		double result = (a/b)*100;
		String formattedResult = String.format("%.2f", result);
		return Double.parseDouble(formattedResult);
	}

	public static BigDecimal addBigDecimal(String a, String b){
		BigDecimal aa = new BigDecimal(a);
		BigDecimal bb = new BigDecimal(b);
		return aa.add(bb);
	}

	public static void main(String[] args) throws Exception {

		Double double1= new Double(66);
		Double double2= new Double(6677);
		System.out.println(divideAB(double1,double2));


		Double double3= new Double(123.100);
		Double double4= new Double(123.00);

//		System.out.println(get100(1, 3, 4));
//		System.out.println(get1000(2, 3, 4));

		BigDecimal result = new BigDecimal("0");
		for (int i = 1; i < 4; i++) {
			result=addBigDecimal(result.toString(),i+"");
			System.out.println(result.toString());
		}
	}

}